package main

import (
	"fmt"
	"gitee.com/guoliben/kydlp-doctotext"
	"io/ioutil"
	"os"
	"unsafe"
)

/***DEBUG START FOR BUILD DOCTOTEXT */
func callback_string(path string, size int64, filetype string, text string, length int64, context interface{}) (int /*0继续匹配，非0停止匹配*/, error) {
	fmt.Println()
	fmt.Println(text)
	return 0, nil
}
func callback_slice(path string, size int64, filetype string, text []byte, length int64, context interface{}) (int /*0继续匹配，非0停止匹配*/, error) {
	fmt.Println()
	fmt.Println(*(*string)(unsafe.Pointer(&text)))
	return 1, nil
}

func main() {
	filepath := "trace.go.gz1"
	filepath = "/home/test/storage通用数据存储/code/kydlp-doctotext/pack/test-pack/Packages.gz"
	filepath = "/home/test/storage通用数据存储/F/big-window-file/test-msp/ca1b5324.msp"
	filepath = "/home/test/storage通用数据存储/F/test-zip/1/src/src.zip"
	filepath = "/home/zhuxizhi/桌面/desktop/麒麟软件相关/测试样本/luhn算法.png"
	filepath = "/home/zhuxizhi/桌面/desktop/麒麟软件相关/专利相关.zip"

	file, err := os.Open(filepath)
	if err != nil {
		fmt.Println("Cannot open file:", err)
		return
	}
	defer file.Close()

	bytes, _ := ioutil.ReadAll(file)
	fmt.Println(len(bytes))

	// TODO : ~ TO BE DELETE 临时测试验证demo
	kydlp_doctotext.Init()

	//fmt.Println(kydlp_doctotext.ExtractStringTextFromFileWithCallback("demo.doc", 0, callback_string, nil))
	//fmt.Println(kydlp_doctotext.ExtractStringTextFromFile("demo.doc", 0))
	//fmt.Println(kydlp_doctotext.ExtractStringTextFromFile("demo.et", 0))
	//fmt.Println(kydlp_doctotext.ExtractStringTextFromBuffer("demo.et", bytes, 0))
	//fmt.Println(kydlp_doctotext.ExtractStringTextFromFile("demo.xls", 0))
	//fmt.Println(kydlp_doctotext.ExtractStringTextFromFile("demo.xls", 0))
	//fmt.Println(kydlp_doctotext.ExtractStringTextFromFile("333333.xlsx", 0))
	//fmt.Println(kydlp_doctotext.ExtractStringTextFromBuffer("333333.xlsx", bytes, 0))
	//fmt.Println(kydlp_doctotext.ExtractStringTextFromFile("333333.pdf", 0))
	//fmt.Println(kydlp_doctotext.ExtractStringTextFromFile("kylin.pdf", 0))
	//fmt.Println(kydlp_doctotext.ExtractStringTextFromBuffer("333333.pdf", bytes, 0))
	//fmt.Println(kydlp_doctotext.ExtractStringTextFromBuffer("kylin.pdf", bytes, 0))
	//fmt.Println(kydlp_doctotext.ExtractStringTextFromFile("kysec的实现机制-服务器-题目.xlsx", 0))
	//fmt.Println(kydlp_doctotext.ExtractStringTextFromFile("加密2.xls", 0))
	//fmt.Println(kydlp_doctotext.ExtractStringTextFromFile("xls.xls", 0))
	//fmt.Println(kydlp_doctotext.ExtractStringTextFromFile("osg.pdf", 0))

	//fmt.Println(kydlp_doctotext.ExtractStringTextFromFile("tquery.dll.mui", 0))
	//fmt.Println(kydlp_doctotext.ExtractStringTextFromFile("/media/test/Windows/Windows/WinSxS/Manifests/msil_system.web.dynamicdata.design.resources_31bf3856ad364e35_10.0.22000.1_en-us_340fd8a8565adb43.manifest", 0))
	//fmt.Println(kydlp_doctotext.ExtractStringTextFromFile("333333.pdf", 0))

	//kydlp_doctotext.ExtractStringTextFromFile("trace.go2", 0)  // trace.go MEM 190M
	//kydlp_doctotext.ExtractStringTextFromFileWithCallback("trace.go2", 0, callback_string, nil) // trace.go MEM 29M
	//kydlp_doctotext.ExtractStringTextFromBuffer("333333.pdf", bytes, 0) //trace.go MEM  445M(base input 447)
	//kydlp_doctotext.ExtractStringTextFromBufferWithCallback("333333.pdf", bytes, 0, callback_string, nil) //trace.go MEM  445M(readAll size)

	//kydlp_doctotext.ExtractStringTextFromFile("trace.go.gz1", 0) // trace.go.gz1 MEM 180M
	//kydlp_doctotext.ExtractStringTextFromFileWithCallback("trace.go.gz1", 0, callback_string, nil) // trace.go.gz1 MEM 180M
	//kydlp_doctotext.ExtractStringTextFromBuffer("eeeeeeeeeempty", bytes, 0) // trace.go.gz1 400-500
	//kydlp_doctotext.ExtractStringTextFromFileWithCallback("trace.go.gz1", 0, callback_string, nil)

	//kydlp_doctotext.ExtractStringTextFromFile("/home/test/storage通用数据存储/code/kydlp-doctotext/pack/test-pack.tar.gz", 0) //
	//kydlp_doctotext.ExtractStringTextFromFileWithCallback("/home/test/storage通用数据存储/code/kydlp-doctotext/pack/test-pack.tar", 0, callback_string, nil)    //
	//kydlp_doctotext.ExtractStringTextFromFileWithCallback("/home/test/storage通用数据存储/code/kydlp-doctotext/pack/test-pack.tar.gz", 0, callback_string, nil) //
	//kydlp_doctotext.ExtractStringTextFromFile("/home/test/storage通用数据存储/code/kydlp-doctotext/pack/test-pack/Packages.gz", 0) //
	//kydlp_doctotext.ExtractStringTextFromBuffer("eeeeeeeeeempty", bytes, 0) // trace.go.gz1 400-500
	//kydlp_doctotext.ExtractStringTextFromFile("test-zip2.tar.gz", 0) //
	//kydlp_doctotext.ExtractStringTextFromFile("/home/test/storage通用数据存储/code/kydlp-doctotext/pack/test-pack.tar.gz", 0) //

	//kydlp_doctotext.ExtractStringTextFromFile("/home/test/storage通用数据存储/F/test-zip/1/src/src.zip", 0) //src.zip 700M
	//kydlp_doctotext.ExtractStringTextFromBuffer("eeeeeeeeeempty", bytes, 0) // src.zip 700M
	//kydlp_doctotext.ExtractStringTextFromFileWithCallback(filepath, 0, callback_string, nil) //
	kydlp_doctotext.ExtractStringTextFromBufferWithCallback(filepath, bytes, 0, callback_string, nil) //
	kydlp_doctotext.ExtractTextFromBufferWithCallback(filepath, bytes, 0, callback_slice, nil) //

	kydlp_doctotext.Destroy()

	/**DEBUG TODO END**/
	fmt.Println("\n结束")

	select {}
}
